#include <iostream>
#include <regex>

int main()
{
    int type;
    char data[18] = { 0 };
    std::cout << "0: 手机号\n1: 身份证\n请选择识别类型: ";
    std::cin >> type;
    std::regex e0("^1(3\\d|47|5([0-3]|[5-9])|8(0|2|[5-9]))\\d{8}$");
    std::regex e1("^\\d{6}(18|19|20)?\\d{2}(0[1-9]|1[012])(0[1-9]|[12]\\d|3[01])\\d{3}(\\d|[xX])$");
    switch(type) {
        case 0:
            std::cout << "请输入手机号：";
            std::cin >> data;
            if (std::regex_match(data, e0)) {
                std::cout << "手机号正确" << std::endl;
            } 
            else {
                std::cout << "非法手机号！" << std::endl;
            }
            break;
        case 1:
            std::cout << "请输入身份证号: ";
            std::cin >> data;
            if (std::regex_match(data, e1)) {
                std::cout << "身份证号正确" << std::endl;
            } 
            else {
                std::cout << "非法身份证号！" << std::endl;
            }
            break;
        default:
            std::cout << "选择类型错误！" << std::endl;
            break;
    }

    return 0;
}